package com.ruoyi.ax.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ax.domain.AxMemberApplyRecord;
import com.ruoyi.ax.service.IAxMemberApplyRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员申请记录Controller
 * 
 * @author ruoyi
 * @date 2025-05-19
 */
@RestController
@RequestMapping("/ax/AxMemberApplyRecord")
public class AxMemberApplyRecordController extends BaseController
{
    @Autowired
    private IAxMemberApplyRecordService axMemberApplyRecordService;

    /**
     * 查询会员申请记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AxMemberApplyRecord axMemberApplyRecord)
    {
        startPage();
        List<AxMemberApplyRecord> list = axMemberApplyRecordService.selectAxMemberApplyRecordList(axMemberApplyRecord);
        return getDataTable(list);
    }

    @GetMapping("/mylist")
    public TableDataInfo mylist(AxMemberApplyRecord axMemberApplyRecord)
    {
        startPage();
        axMemberApplyRecord.setApplyerUserid(SecurityUtils.getUserId()+"");
        List<AxMemberApplyRecord> list = axMemberApplyRecordService.selectAxMemberApplyRecordList(axMemberApplyRecord);
        return getDataTable(list);
    }
    // 获取我的审核信息
    @GetMapping("/myAuditInfo")
    public AjaxResult myAuditList(AxMemberApplyRecord axMemberApplyRecord)
    {
        startPage();
        axMemberApplyRecord.setApplyerUserid(SecurityUtils.getUserId()+"");
        List<AxMemberApplyRecord> list = axMemberApplyRecordService.selectAxMemberApplyRecordList(axMemberApplyRecord);
        if(list.size()==0){
            axMemberApplyRecord.setAuditStatus("2");
        }else{
            axMemberApplyRecord = list.get(0);
        }
        return success(axMemberApplyRecord);
    }


    /**
     * 导出会员申请记录列表
     */
    @Log(title = "会员申请记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AxMemberApplyRecord axMemberApplyRecord)
    {
        List<AxMemberApplyRecord> list = axMemberApplyRecordService.selectAxMemberApplyRecordList(axMemberApplyRecord);
        ExcelUtil<AxMemberApplyRecord> util = new ExcelUtil<AxMemberApplyRecord>(AxMemberApplyRecord.class);
        util.exportExcel(response, list, "会员申请记录数据");
    }

    /**
     * 获取会员申请记录详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(axMemberApplyRecordService.selectAxMemberApplyRecordById(id));
    }



    /**
     * 新增会员申请记录
     */
    @Log(title = "h5会员申请", businessType = BusinessType.INSERT)
    @PostMapping("/appAdd")
    public AjaxResult appAdd(@RequestBody AxMemberApplyRecord axMemberApplyRecord)
    {
        return toAjax(axMemberApplyRecordService.userApply(axMemberApplyRecord));
    }

    @Log(title = "会员申请审核", businessType = BusinessType.INSERT)
    @PostMapping("/audit")
    public AjaxResult applyAudit(@RequestBody AxMemberApplyRecord axMemberApplyRecord)
    {
        return toAjax(axMemberApplyRecordService.userApplyAudit(axMemberApplyRecord));
    }


    /**
     * 新增会员申请记录
     */
    @Log(title = "会员申请记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AxMemberApplyRecord axMemberApplyRecord)
    {
        return toAjax(axMemberApplyRecordService.insertAxMemberApplyRecord(axMemberApplyRecord));
    }

    /**
     * 修改会员申请记录
     */
    @Log(title = "会员申请记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AxMemberApplyRecord axMemberApplyRecord)
    {
        return toAjax(axMemberApplyRecordService.updateAxMemberApplyRecord(axMemberApplyRecord));
    }

    /**
     * 删除会员申请记录
     */
    @Log(title = "会员申请记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(axMemberApplyRecordService.deleteAxMemberApplyRecordByIds(ids));
    }
}
